<?php

namespace app\admin\controller;

use app\admin\model\chase\Order;
use app\admin\model\chase\RechargeOrder;
use app\admin\model\chase\User;
use app\admin\model\chase\UserVip;
use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        //今日收入总额
        $today_order_amount = Order::getTodayTotalAmount();
        $today_recharge_amount = RechargeOrder::getTodayTotalAmount();
        $today_amount = $today_order_amount + $today_recharge_amount;
        //服务收入总额
        $order_total_amount = Order::getTotalAmount();
        //充值收入总额
        $recharge_total_amount = RechargeOrder::getTotalAmount();
        //用户总数
        $total_user = User::getUserCount();
        //今日新增用户数
        $today_user = User::getTodayUserCount();
        //会员总数
        $total_vip = User::getVipCount();
        //今日新增会员数
        $today_vip = User::getTodayVipCount();
        //待服务数
        $service_await = Order::getCountByStatus(1);
        //待核销数
        $payment_await = Order::getCountByStatus(0);
        //待退款数
        $refund_await = Order::getCountByStatus(4);
        //会员等级
        $user_vips = UserVip::getUserVip();
        
        $this->view->assign([
            'today_amount' => $today_amount,
            'order_total_amount' => $order_total_amount,
            'recharge_total_amount' => $recharge_total_amount,
            'total_user' => $total_user,
            'today_user' => $today_user,
            'total_vip' => $total_vip,
            'today_vip' => $today_vip,
            'service_await' => $service_await,
            'payment_await' => $payment_await,
            'refund_await' => $refund_await,
            'userVips' => $user_vips,
        ]);

        return $this->view->fetch();
    }

}
